﻿using System;
using System.Text;
using System.Web.Mvc;
using SportsStore.WebUI.Models;

namespace SportsStore.WebUI.HtmlHelpers {

  public static class PagingHelpers {

    public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, Func<int, string> pageUrl) {
      var result = new StringBuilder();
      
      for (int i = 1; i <= pagingInfo.TotalPages; i++) {
        var tagBuilder = new TagBuilder("a"); // Construct an <a> tag
        tagBuilder.MergeAttribute("href", pageUrl(i));
        tagBuilder.InnerHtml = i.ToString();
        if (i == pagingInfo.CurrentPage)
          tagBuilder.AddCssClass("selected");
        var tag = tagBuilder.ToString();

        result.Append(tag);
      }

      return MvcHtmlString.Create(result.ToString());
    }

  }

}